package alp.starcode.sanping.crawler;

import alp.starcode.sanping.common.BizConstant;
import alp.starcode.sanping.crawler.impl.CnGxbServiceImpl;
import alp.starcode.sanping.crawler.impl.HeBeiGxbServiceImpl;
import alp.starcode.sanping.information.service.InformationService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * TODO 数据获取定时器
 *
 * @date 2024/3/13 16:07
 */
@Service
public class InfoCrawlerService {

    @Resource
    private InformationService informationService;

    /**
     * 每天早上6点执行
     */
    @Scheduled(cron = "0 0 6 * * ?")
    public void executeInfoDateAMTask() {
        executeInfoDate();
    }

    /**
     * 每天晚上6点执行
     */
    @Scheduled(cron = "0 0 18 * * ?")
    public void executeInfoDatePMTask() {
        executeInfoDate();
    }

    /**
     * 将数据获取汇总执行
     */
    public void executeInfoDate() {
        // 全国数据
        CnGxbServiceImpl.run();
        informationService.addBatch(BizConstant.SP_INFORMATION_LIST);
        // 河北数据
        HeBeiGxbServiceImpl.run();
        informationService.addBatch(BizConstant.SP_INFORMATION_LIST);
    }

}
